import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

// 配置我们自己的路由规则
const routes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login'),
  },
  {
    path: '/',
    redirect: '/home',
    name: 'layout',
    component: () => import('@/views/layout'),
    children: [
      {
        path: '/home', // 路由为空就是默认子路由，这个默认子路由只能有一个
        name: 'home',
        component: () => import('@/views/home'),
      },
      {
        path: '/qa',
        name: 'qa',
        component: () => import('@/views/qa'),
      },
      {
        path: '/video',
        name: 'video',
        component: () => import('@/views/video'),
      },
      {
        path: '/my',
        name: 'my',
        component: () => import('@/views/my'),
      },
    ],
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/artical_search/index.vue'),
  },
  {
    path: '/artiacl/:articalId',
    name: 'artiacl',
    component: () => import('@/views/artical/index.vue'),
    props: true,
    // 开启路由传参，说白了就是将路由参数:articalId映射到组件的props里面
  },
];

const router = new VueRouter({
  routes,
});

export default router;
